package com.zhike.handler;

import net.cellcloud.talk.dialect.ActionDialect;

import com.zhike.core.Failure;

import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.EditText;


public class IncidentDetailHandler extends Handler {

	public static final int MSG_ACTION = 1;
	public static final int MSG_CONNECT = 2;
	public static final int MSG_DISCONNECT = 3;
	public static final int MSG_FAILURE = 5;

	private EditText summaryText;

	public IncidentDetailHandler(EditText summaryText) {
		this.summaryText=summaryText;
	}

	@Override
	public void handleMessage(Message msg) {
		switch (msg.what) {
		case MSG_ACTION:
			ActionDialect action = (ActionDialect) msg.obj;
			Log.i("admin", "[I] Action: " + action.getAction() + "\n");
			Log.i("admin", "    N: " + action.getAction() + "\n");
			Log.i("admin", "    V: " + action.getParamAsString("data") + "\n");
			
			this.summaryText.append(action.getParamAsString("data"));
			break;
		case MSG_CONNECT:
			Log.i("admin", "[I] Connect: " + msg.obj + "\n");
			break;
		case MSG_DISCONNECT:
			Log.i("admin", "[I] Disconnect: " + msg.obj + "\n");
			break;
		case MSG_FAILURE:
			Failure failure = (Failure) msg.obj;
			Log.i("admin",
					"[F] Failed #" + failure.getCode() + " - "
							+ failure.getDescription() + "\n");
			break;
		default:
			break;
		}
	}
}
